# -*- coding: utf-8 -*-
import scrapy
from myscrapy.items import MyscrapyItem

class LagouSpider(scrapy.Spider):
    name = 'lagou'
    allowed_domains = ['www.lagou.com']
    start_urls = ['https://www.lagou.com/hangzhou-zhaopin/Python/?filterOption=3&sid=ba27ceada2e942c5a3169ca0d82affd4']

    def parse(self, response):
        items = []
        for i in range(1,16):
            item = MyscrapyItem()
            workPlace = response.xpath('//*[@id="s_position_list"]/ul/li[{0}]/div[1]/div[1]/div[1]/a/span/em/text()'.format(i)).extract()[0]  # 工作地点
            pay = response.xpath('//*[@id="s_position_list"]/ul/li[{0}]/div[1]/div[1]/div[2]/div/span/text()'.format(i)).extract()[0]  # 工资上限
            education = response.xpath('//*[@id="s_position_list"]/ul/li[{0}]/div[1]/div[1]/div[2]/div/text()'.format(i)).extract()[2].strip()  # 教育程度要求
            company = response.xpath('//*[@id="s_position_list"]/ul/li[{0}]/div[1]/div[2]/div[1]/a/text()'.format(i)).extract()[0]  # 公司名称
            fieldTag = response.xpath('//*[@id="s_position_list"]/ul/li[{0}]/div[1]/div[2]/div[2]/text()'.format(i)).extract()[0].strip()  # 公司所在领域的标签
            item['workPlace']=workPlace
            item['pay']=pay
            item['education']=education
            item['company']=company
            item['fieldTag']=fieldTag
            items.append(item)
        return items
        pass
